$NG.AllReady(function (page, { useDataIndexChange, useUpdateRow,useClick, useValuesChange, useUpdateRows }) {
    const mstform = $NG.getCmpApi("p_form_document_handover_m");
    const dgrid1 = $NG.getCmpApi("p_form_document_handover_d");
    useValuesChange(({ args }) => {
    $NG.execServer('getPtInfoByPhid', 
        { phid: $NG.getCmpApi('p_form_document_handover_m').getItem('phid_pc').getValue() }, 
        function (res) {
        const datas = JSON.parse(res.data)[0].extendObjects;
        //帮助字段赋值
        $NG.updateState((updater) => {
            //【注意这里的表名不能为控件ID，必须要是表名】
            updater.data.p_form_document_handover_m.setProps({
                u_pc_no: datas.pc_no,
                u_xmjl:{ 
                    value:datas.project_manager_phid, 
                    label:datas.project_manager_name
                }
                
            });
        });

    });
}, 'p_form_document_handover_m.phid_pc');  
useValuesChange(({args})=>{
    console.log(`args`,args);
    getProjectZlMbInfo()
},"p_form_document_handover_m.u_mb")
$NG.updateState((updater)=>{
        updater.data.p_form_document_handover_m.setProps({
            u_jjsj:formatDate(new Date(), "yyyy-mm-dd")
        })
    })
    function formatDate(dateStr, outputFormat) {
    const date = new Date(dateStr);

    if (isNaN(date)) {
        return "无效的日期字符串";
    }

    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');

    let formattedDate;

    switch (outputFormat) {
        case "yyyy-mm-dd":
            formattedDate = `${year}-${month}-${day}`;
            break;
        case "yyyy-mm-dd HH:mm":
            formattedDate = `${year}-${month}-${day} ${hours}:${minutes}`;
            break;
        // 可以根据需要继续添加其他格式的处理逻辑
        default:
            formattedDate = "不支持的输出格式";
    }

    return formattedDate;
}


function getProjectZlMbInfo(){
    const phid = mstform.getItem("u_mb").getValue()
    if(!phid) return
    $NG.execServer("getProjectZlMbInfo",{phid},(res)=>{
        if(res.count == 0) return
        const _data = JSON.parse(res.data).reduce((value,item)=>{
            const el = item.extendObjects
            value.push({
                u_gdjd:el.u_gdjd,
                u_gdjd_EXName:el.u_gdjd_exname,
                u_zlmc:el.u_zlmc,
                u_yq:el.u_yq
            })
            return value
        },[])
        dgrid1.addRows(_data)
    })
}

  });
   